package com.utils;


import org.springframework.context.ApplicationContext;

import java.util.Arrays;
import java.util.List;

/**
 * @author jokerjt
 * @version 1.0
 * @date 2024/9/15 17:27
 */
public class SpringContextUtil {

    private static ApplicationContext ac;

    public static <T>  T getBean(String beanName,Class<T> clazz) {
        T bean = ac.getBean(beanName, clazz);
        return bean;
    }
    public static<T> T getBean(String beanName) {
        T bean = (T) ac.getBean(beanName);
        return bean;
    }

    public static<T> T getBean(Class clazz) {
        T bean = (T) ac.getBean(clazz);
        return bean;
    }

    public static List<String> getAllBeansName(){
        List<String> beanNames = Arrays.asList(ac.getBeanDefinitionNames());
        return beanNames;
    }

    public static void setAc(ApplicationContext applicationContext){
        ac = applicationContext;
    }
}
